package com.smart_campus.bus.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.bus.vo.CommentVo;
import com.smart_campus.bus.domain.Comment;
import com.smart_campus.bus.mapper.CommentMapper;
import com.smart_campus.bus.service.CommentService;
import com.smart_campus.sys.common.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;


    /**
     * 查询全部评论
     * */
    @Override
    public DataGridView selComment(CommentVo commentVo) {
        Page<Object> page = PageHelper.startPage(commentVo.getPage(),commentVo.getLimit());
        List<CommentVo> list = commentMapper.selComment(commentVo);
        return new DataGridView(page.getTotal(),list);
    }

    /**
     * 根据文章id查询评论
     *
     * @return*/
    @Override
    public List<CommentVo> selCommentByJournalId(int jid) {
        return commentMapper.selCommentByJournalId(jid);
    }

    @Override
    public Boolean delCommentById(Integer id) {
        return commentMapper.delCommentById(id);
    }

    @Override
    public Comment writeComment(Comment comment) {
         commentMapper.writeComment(comment);
        System.out.println("comment = " + comment.toString());
         return comment;
    }

    @Override
    public List<Comment> selbyid(Integer id) {
        return commentMapper.selbyid(id);
    }


}
